<div data-token-type="<%= @type %>">
  <h6 class="dropdown-header" style="margin-left: 5px;">
    <%= @type %> (<span data-number-of-tokens-by-type="<%= @type %>"><%= Enum.count(@token_balances)%></span>)
  </h6>

  <%= for {token_balance, token} <- @token_balances do %>
    <div
      class="border-bottom"
      data-dropdown-token-balance-test
      data-token-name="<%= token_name(token) %>"
      data-token-symbol="<%= token_symbol(token) %>"
    >
      <% path = cond do
          token_balance.token_type == "ERC-721" && !is_nil(token_balance.token_id) -> token_instance_path(@conn, :show, token.contract_address_hash, to_string(token_balance.token_id))
          token_balance.token_type == "ERC-1155" && !is_nil(token_balance.token_id) -> token_instance_path(@conn, :show, token.contract_address_hash, to_string(token_balance.token_id))
          true -> token_path(@conn, :show, to_string(token.contract_address_hash))
        end
      %>
      <%= link(
            to: path,
            class: "dropdown-item"
          ) do %>
        <div class="row dropdown-row wh-sp">
          <%= if Application.get_env(:block_scout_web, :display_token_icons) do %>
            <% chain_id_for_token_icon = Application.get_env(:block_scout_web, :chain_id) %>
            <% address_hash = token.contract_address_hash %>
            <%=
              render BlockScoutWeb.TokensView,
              "_token_icon.html",
              chain_id: chain_id_for_token_icon,
              address: Address.checksum(address_hash),
              additional_classes: ["token-wallet-icon"]
            %>
          <% end %>
          <p class="mb-0 col-md-6 pl-0 pr-0 el-1 flex-grow-2 <%= if !Application.get_env(:block_scout_web, :display_token_icons), do: "ml-5px" %>"><%= token_name(token) %>
          </p>
          <%= if token.fiat_value && token.decimals do %>
            <p class="mb-0 col-md-6 text-right usd-total">
              <span data-selector="token-balance-usd" data-usd-value="<%= Chain.balance_in_fiat(token_balance, token) %>"></span>
            </p>
          <% end %>
        </div>
        <div class="row dropdown-row wh-sp">
          <%= if token.fiat_value do %>
            <p class="mb-0 text-right text-muted usd-rate">
              <span data-selector="token-price" data-token-usd-value="<%= token.fiat_value %>"></span>
            </p>
          <% end %>
        </div>
        <div class="row dropdown-row wh-sp">
          <p class="mb-0 ml-5px dropdown-amount <%= if Application.get_env(:block_scout_web, :display_token_icons), do: "ml-20px" %>">
            <%= if token_balance.token_type == "ERC-721" && !is_nil(token_balance.token_id) do %>
              1
            <% else %>
              <%= format_according_to_decimals(token_balance.value, token.decimals) %> <%= token_symbol(token) %>
            <% end %>
            <%= if (token_balance.token_type == "ERC-721" && !is_nil(token_balance.token_id)) or token_balance.token_type == "ERC-1155" do %>
              <%= " TokenID " <> to_string(token_balance.token_id) %>
            <% end %>
          </p>
        </div>
      <% end %>
    </div>
  <% end %>
</div>
